import {
  Body,
  Controller,
  Delete,
  Get,
  Inject,
  Param,
  Patch,
  Post,
  Query,
} from '@nestjs/common';
import { PaginationQueryDto } from 'src/common/dto/pagination-query.dto';
import { CreateArticlesDto } from './dto/create-articles.dto';
import { UpdateArticlesDto } from './dto/update-articles.dto';
import { ArticlesService } from './articles.service';
import { REQUEST } from '@nestjs/core';
import { Request } from 'express';

@Controller('articles')
export class ArticlesController {
  constructor(
    private readonly helloService: ArticlesService,
    @Inject(REQUEST) private readonly request: Request,
  ) {
    console.log('create instance in the request');
  }
  @Get()
  findAll(@Query() paginationQuery: PaginationQueryDto) {
    return this.helloService.findAll(paginationQuery);
  }

  @Get(':id')
  findOne(@Param() { id }) {
    return this.helloService.findOne(id);
  }

  @Post()
  create(@Body() createArticlesDto: CreateArticlesDto) {
    return this.helloService.create(createArticlesDto as any);
  }

  @Patch(':id')
  update(
    @Param() { id }: { id: string },
    @Body() updateArticlesDto: UpdateArticlesDto,
  ) {
    return this.helloService.update(id, updateArticlesDto as any);
  }

  @Delete(':id')
  remove(@Param() { id }: { id: string }) {
    return this.helloService.remove(id);
  }
}
